
package com.wwy.monitor.service.acl;

import com.alibaba.buc.api.exception.BucException;
import com.alibaba.buc.api.permission.PermissionResult;
import com.wwy.monitor.model.vo.PermissionInfoResult;
import com.wwy.monitor.service.acl.helper.PermissionServiceHelper;
import com.wwy.monitor.service.acl.helper.UrlCheckServiceHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Title: PermissionService
 * Description:
 * Date: 16/6/22 ä¸å9:04
 *
 * @author jl107065 jl107065@autonavi.com
 * @see
 */
@Service("acl_PermissionService")
public class PermissionService {
    @Autowired
    private PermissionServiceHelper permissionServiceHelper;
    @Autowired
    private UrlCheckServiceHelper urlCheckServiceHelper;
    @Autowired
    private AclInfo aclInfo;

    public PermissionInfoResult check(Long userId, String permissionName) throws BucException {
//å¤æ­å½åç¨æ·æ¯å¦æ¥æå½åæé
        Boolean hasPermission = permissionServiceHelper.hasPermissionOf(userId, permissionName);
//æ ¹æ®æéè±æåç§°è·åæéè¯¦ç»ä¿¡æ¯
        PermissionResult permissionResult = urlCheckServiceHelper.getPermissionByName(permissionName);
        PermissionInfoResult permissionInfoResult = new PermissionInfoResult();
        permissionInfoResult.setApplyUrl(aclInfo.getPermissionApplyUrl());
        if (permissionResult != null) {
            permissionInfoResult.setPermissionName(permissionResult.getPermissionTitle());
        }
        permissionInfoResult.setHasPermission(hasPermission);
        return permissionInfoResult;
    }
}